<template>
	<view>
		<button @click="login">登陆</button>
	</view>
</template>

<script>
	const app = getApp();
	const db = uniCloud.database();
	const dbCmd = db.command;
	const db_collection = 'code';
	
	export default {
		data() {
			return {
				codeId: ''
			}
		},
		onLoad(event) {		
			this.codeId = event.codeid;
		},
		methods: {
			async login(e) {
				const token = uni.getStorageSync('uni_id_token')
				const token_expired = uni.getStorageSync('uni_id_token_expired')
				db.collection(db_collection).doc(this.codeId)
				.update({
					uid: app.globalData.userInfo._id,
					token: token,
					token_expired: token_expired
				}).then(res => {
					console.log(res)
				})
			}
		}
	}
</script>

<style>

</style>
